from peewee import CharField

from application.db import get_database_connection
from application.db.mysql_db.base_mysql_model import BaseMysqlModel
from application.db.redis_db.base_redis import RedisManager


class CnArticleJournalPlatformIdRelation(BaseMysqlModel):
    """中文文献库期刊列表，存储期刊在第三方平台上的ID信息"""
    journal_code = CharField(max_length=32, index=True)  # 期刊代码，表cn_article_journal_list标识
    platform_id = CharField(max_length=255, index=True)  # 期刊在第三方平台上的ID
    platform_code = CharField(max_length=64)  # 平台代码，取值["issn"(ISSN号), "eissn"(E-ISSN号), "cnsn"(国内统一连续出版物号，即CN刊号), "yiigle"(中华医学数据库标识的期刊ID), "cnki"(知网标识的期刊ID)]

    class Meta:
        table_name = 'cn_article_journal_platform_id_relation'
        database = get_database_connection('default')  # 使用默认数据库


if __name__ == '__main__':
    #
    data=CnArticleJournalPlatformIdRelation.select().dicts()
    redis_manager = RedisManager()
    redis_conn = redis_manager.get_connection()
    for i in data:
        r_key=f"CN_JOURNAL_CODE_CACHE:{i["platform_id"]}"
        redis_conn.set(r_key, i['journal_code'])  # 60秒后过期
